package com.zhiyou100.springbootweather.controller;

import com.alibaba.fastjson.JSON;
import com.zhiyou100.springbootweather.pojo.City;
import com.zhiyou100.springbootweather.pojo.WeatherResponse;
import com.zhiyou100.springbootweather.service.ICityService;
import com.zhiyou100.springbootweather.service.IWeatherDataService;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class WeatherDataController {
    @Resource
    private IWeatherDataService weatherDataService;


    @GetMapping("cityName")
    public WeatherResponse cityName(String name) {

        return weatherDataService.getDataByCityName(name);
    }


    /**
     * 根据id查询
     *
     * @param id
     * @throws IOException
     */
    @RequestMapping("cityId")
    @ResponseBody //返回json数据
    public WeatherResponse cityId(String id) {
        WeatherResponse dataByCityId1 = weatherDataService.getDataByCityId(id);//查询通过id 拿到数据
        return dataByCityId1;
    }

    /**
     *
     * 跳转到 界面上
     * @param model
     * @return
     */
    @RequestMapping("test")
    public String demo(Model model) {

        return "weatherday";
    }



}
